package com.zmc.lostfound.post.controller;

import com.zmc.lostfound.common.utils.PageResult;
import com.zmc.lostfound.common.utils.Result;
import com.zmc.lostfound.common.valid.AddGroup;
import com.zmc.lostfound.common.valid.UpdateGroup;
import com.zmc.lostfound.post.entity.PostReportEntity;
import com.zmc.lostfound.post.service.PostReportService;
import com.zmc.lostfound.post.vo.PostReportQueryVO;
import com.zmc.lostfound.post.vo.PostReportSaveVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author WJS
 * @description 帖子举报管理接口
 * @date 2023-07-05 15:49:44
 */
@RestController
@RequestMapping("/postReport")
@Api(value = "帖子举报管理接口", tags = "帖子举报管理接口")
public class PostReportController {

    private final PostReportService postReportService;

    public PostReportController(PostReportService postReportService) {
        this.postReportService = postReportService;
    }

    @ApiOperation("多条件查询帖子举报信息")
    @GetMapping("/query/page")
    public Result queryPage(@Validated PostReportQueryVO postReportQueryVO) {
        PageResult pageResult = postReportService.queryPage(postReportQueryVO);
        return Result.ok("查询成功").put("pageResult", pageResult);
    }

    @ApiOperation("按主键id查询帖子举报信息")
    @GetMapping("/query/infoById/{id}")
    public Result queryInfoById(@PathVariable("id") Long id) {
        PostReportEntity postReportInfo = postReportService.queryInfoById(id);
        return Result.ok("查询成功").put("postReportInfo", postReportInfo);
    }

    @ApiOperation("用户举报帖子")
    @PostMapping("/insertPostReport")
    public Result insertPostReport(@RequestBody @Validated(value = {AddGroup.class}) PostReportSaveVO postReportSaveVO) {
        return postReportService.insertPostReport(postReportSaveVO);
    }

    @ApiOperation("修改帖子举报信息")
    @PutMapping("/updatePostReport")
    public Result updatePostReport(@RequestBody @Validated(value = {UpdateGroup.class}) PostReportSaveVO postReportSaveVO) {
        return postReportService.updatePostReport(postReportSaveVO);
    }

    @ApiOperation("按主键id删除帖子举报信息")
    @DeleteMapping("/deleteById/{id}")
    public Result deleteById(@PathVariable("id") Long id) {
        return postReportService.deleteById(id);
    }

    @ApiOperation("按帖子id删除帖子举报信息")
    @DeleteMapping("/deleteBatchByPostId/{postId}")
    public Result deleteBatchByPostId(@PathVariable("postId") Long postId) {
        return postReportService.deleteBatchByPostId(postId);
    }

}
